<?php

class Mhs extends CI_Controller {

    function __construct() {
        parent::__construct();
        $this->load->library('parser');
        $this->load->model('uwd');
        $login = $this->session->userdata('login');
        $privilege = $this->session->userdata('pri');
        if ($login != TRUE || $privilege != 3) {
            redirect('main/logout');
        }
    }

    function index() {
        redirect('mhs/password');
    }

    function password() {
        $data['page'] = 'Ganti Password | Universitas Widya Dharma';
        $id = $this->session->userdata('username');
        $da = $this->uwd->mhs_nama($id);
        $data['nama'] = $da[0]->nama;
        $this->parser->parse('mhs/header', $data);
        $this->parser->parse('mhs/password', $data);
        $this->load->view('themes/footer');
    }

    function password_update() {
        $lama = $this->input->post('lama');
        $id = $this->session->userdata('username');
        $cek = $this->uwd->passlama($id, $lama);
        if ($cek == TRUE) {
            $pass = array(
                'password' => $this->input->post('baru')
            );
            $this->uwd->passbaru($id, $pass);
            $da = $this->uwd->nama($id);
            $data['nama'] = $da[0]->nama;
            $data['page'] = 'Update Password | Universitas Widya Dharma';
            $data['username'] = $id;
            $data['alert'] = '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert">×</button><strong>Password berhasil dirubah.</strong></div>';
            $this->parser->parse('mhs/header', $data);
            $this->parser->parse('themes/alert', $data);
            $this->load->view('themes/footer');
        } else {
            $data['page'] = 'Update Password | Universitas Widya Dharma';
            $data['username'] = $id;
            $da = $this->uwd->nama($id);
            $data['nama'] = $da[0]->nama;
            $data['alert'] = '<div class="alert alert-error"><button type="button" class="close" data-dismiss="alert">×</button><strong>Password lama tidak cocok.</strong></div>';
            $this->parser->parse('mhs/header', $data);
            $this->parser->parse('themes/alert', $data);
            $this->load->view('themes/footer');
        }
    }

}

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
?>
